package com.sz.ruichar.manager.timmer;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

@Component
public class MsgSchedule 
{
	@Autowired
    private SchedulerFactoryBean schedulerFactoryBean;
	@Value("${delayMsgTimer}")
    private String delayMsgTimer;
	
	public void scheduleJobs() throws SchedulerException 
	{
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        startJob(scheduler,AttachHomeJob.class,delayMsgTimer,"AttachHomeJob","AttachHomeJob_Grp");//到家延误消息定时任务
    }
	
	private void startJob(Scheduler scheduler,Class<?> exeJobClass,String cronExpression,String jobName,String jobGroup) throws SchedulerException
	{
		JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) exeJobClass) .withIdentity(jobName,jobGroup).build(); 
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); 
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withSchedule(scheduleBuilder).build(); 
        scheduler.scheduleJob(jobDetail,cronTrigger); 
	}
	
}
